<?php
    if(!isset($_SESSION['BinhChon']))
    {
        include_once "autoload.php";
    }
    
    $luachon = 1;
    
    if(isset($_POST['luachon']))
    {
        $luachon = $_POST['luachon'];
        
        $binhchon = new binhchonbs();
        $binhchon->MaTuyChon = $luachon;
        $binhchon->DiaChiIp = getenv("REMOTE_ADDR");
        $ret_binhchon = $binhchon->UpdatePoll();
        //$_SESSION['BinhChon'] = true;
    }
    $binhchon = new binhchonbs();
    
    $tuychon = $binhchon->GetPollOption();
    
    $binhchon->MaBinhChon = 1;
    
    $tongluotbinhchon = 0;
    
    $ret_binhchon = $binhchon->GetPollId();
    
    $tilebinhchon = array();
    
    echo "<h3>".$ret_binhchon[0]['TieuDe']."</h3>";
	for($i = 0; $i < ($tuychon != false ? count($tuychon) : 0); $i++)
    {
        $binhchon->MaTuyChon = $tuychon[$i]['MaTuyChon'];
        $in = $binhchon->GetPollVotes();
        $tongluotbinhchon += $in;
        $tilebinhchon[$i] = $in;
    }
    
    echo "<table boder='0'>";
    for($i = 0; $i < ($tuychon != false ? count($tuychon) : 0); $i++)
    {
        $tile = 100*round($tilebinhchon[$i]/$tongluotbinhchon,2);
        echo "<tr>";
            echo "<td style='padding-left: 15px; font-weight: bold; color: #fff;'>";
                echo $tuychon[$i]['TenTuyChon'].": ";
            echo "</td>";
            
            echo "<td style='padding-left: 2px;'>";
                echo "<img src='images/poll.png' width='$tile' height='12'>";
            echo "</td>";
            
            echo "<td style='padding-left: 3px;'>";
                echo $tile."%";
            echo "</td>";
        echo "</tr>";
    }
    echo "</table>";
    
    echo '<br/>';
    echo '<span style="margin-left: 15px; font-weight: bold; color: #738385; height: 20px; line-height: 20px; float: left;"><a style=" float: left; padding-right: 5px;" href="#" onclick="goBack(); return false;"><img src="images/back.png" alt="" title="Trở về" style="width: 20px; height: 20px;" /></a>Tổng số lượt bình chọn là: '.$tongluotbinhchon."</span>";
 ?>
 